package com.tang.campus_market.service.impl;

import com.alipay.api.AlipayApiException;
import com.tang.campus_market.dao.AlipayDao;
import com.tang.campus_market.dao.GoodsDao;
import com.tang.campus_market.dao.OrderDao;
import com.tang.campus_market.entity.Alipay;
import com.tang.campus_market.entity.Order;
import com.tang.campus_market.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Transactional
public class AlipayServiceImpl implements AlipayService {

    @Autowired
    AlipayDao alipayDao;

    @Autowired
    private GoodsDao goodsDao;

    @Autowired
    private OrderDao orderDao;

    @Override
    public void aliPay(Integer outTradeNo) throws AlipayApiException {
        Order order = orderDao.selectById(outTradeNo);
        order.setStatus(2);
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        order.setEndDate(sdf.format(date));
        orderDao.updateById(order);
        goodsDao.updateGoodSaleState("2",order.getGoodId());
    }
}
